package com.citcc.framework.config;


import com.citcc.api.filter.JwtAuthenticationFilter;
import com.citcc.api.filter.JwtUtil;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import com.citcc.api.controller.PayNotifyController;
import com.citcc.api.netty.handle.HeartBeatHandler;
import com.citcc.api.netty.server.ServerHandler;
import com.citcc.api.netty.server.ServerToClient;
import com.citcc.api.netty.xc.xcserver.XcServerHandler;
import com.citcc.api.netty.xc.xcserver.XcServerToClient;
import com.citcc.business.service.CdzAmountDetailService;
import com.citcc.business.service.CdzAppUserService;
import com.citcc.business.service.CdzChargingService;
import com.citcc.business.service.CdzGunService;
import com.citcc.business.service.CdzIndentService;
import com.citcc.business.service.CdzOrderRefundService;
import com.citcc.business.service.CdzRatesService;
import com.citcc.business.service.CdzStakeService;
import com.citcc.business.service.CdzStationService;
import com.citcc.business.service.CdzWarnService;
import com.citcc.business.service.ScanCodeService;

@Component
public class SpringApplication implements ApplicationListener<ContextRefreshedEvent>{

	
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        // 将 ApplicationContext 转化为 WebApplicationContext 
        WebApplicationContext webApplicationContext = 
            (WebApplicationContext)contextRefreshedEvent.getApplicationContext();
        // 从 webApplicationContext 中获取  servletContext 
        //ServletContext servletContext = webApplicationContext.getServletContext();
        // servletContext设置值
       // servletContext.setAttribute("key", "value");
      //初始化孟州公交的809服务
  		//BusiHandler.monitorCenterService=(MonitorCenterService) webApplicationContext.getBean(MonitorCenterService.class);
        ServerHandler.cdzStakeService=(CdzStakeService) webApplicationContext.getBean(CdzStakeService.class);
        ServerHandler.cdzGunService=(CdzGunService) webApplicationContext.getBean(CdzGunService.class);
        ServerToClient.scanCodeService=(ScanCodeService) webApplicationContext.getBean(ScanCodeService.class);
        ServerHandler.cdzIndentService=(CdzIndentService) webApplicationContext.getBean(CdzIndentService.class);
        ServerToClient.cdzIndentService=(CdzIndentService) webApplicationContext.getBean(CdzIndentService.class);
        ServerHandler.cdzAppUserService=(CdzAppUserService) webApplicationContext.getBean(CdzAppUserService.class);
        ServerHandler.scanCodeService=(ScanCodeService) webApplicationContext.getBean(ScanCodeService.class);
        ServerHandler.cdzChargingService=(CdzChargingService) webApplicationContext.getBean(CdzChargingService.class);
        ServerHandler.cdzWarnService=(CdzWarnService) webApplicationContext.getBean(CdzWarnService.class);
        
        ServerHandler.cdzStationService=(CdzStationService) webApplicationContext.getBean(CdzStationService.class);
        ServerHandler.cdzRatesService=(CdzRatesService) webApplicationContext.getBean(CdzRatesService.class);
        ServerHandler.cdzOrderRefundService=(CdzOrderRefundService) webApplicationContext.getBean(CdzOrderRefundService.class);
        ServerHandler.payNotifyController=(PayNotifyController) webApplicationContext.getBean(PayNotifyController.class);
        ServerHandler.cdzAmountDetailService=(CdzAmountDetailService) webApplicationContext.getBean(CdzAmountDetailService.class);
        HeartBeatHandler.cdzGunService=(CdzGunService) webApplicationContext.getBean(CdzGunService.class);
        
        
        XcServerHandler.cdzStakeService=(CdzStakeService) webApplicationContext.getBean(CdzStakeService.class);
        XcServerHandler.cdzGunService=(CdzGunService) webApplicationContext.getBean(CdzGunService.class);
        XcServerHandler.scanCodeService=(ScanCodeService) webApplicationContext.getBean(ScanCodeService.class);
        XcServerHandler.cdzIndentService=(CdzIndentService) webApplicationContext.getBean(CdzIndentService.class);
        XcServerHandler.cdzAppUserService=(CdzAppUserService) webApplicationContext.getBean(CdzAppUserService.class);
        XcServerHandler.scanCodeService=(ScanCodeService) webApplicationContext.getBean(ScanCodeService.class);
        XcServerHandler.cdzChargingService=(CdzChargingService) webApplicationContext.getBean(CdzChargingService.class);
        XcServerHandler.cdzWarnService=(CdzWarnService) webApplicationContext.getBean(CdzWarnService.class);
        XcServerToClient.scanCodeService=(ScanCodeService) webApplicationContext.getBean(ScanCodeService.class);
        
        XcServerHandler.cdzStationService=(CdzStationService) webApplicationContext.getBean(CdzStationService.class);
        XcServerHandler.cdzRatesService=(CdzRatesService) webApplicationContext.getBean(CdzRatesService.class);
        XcServerHandler.cdzOrderRefundService=(CdzOrderRefundService) webApplicationContext.getBean(CdzOrderRefundService.class);
        XcServerHandler.payNotifyController=(PayNotifyController) webApplicationContext.getBean(PayNotifyController.class);
        XcServerHandler.cdzAmountDetailService=(CdzAmountDetailService) webApplicationContext.getBean(CdzAmountDetailService.class);

        //初始化jwt
        JwtAuthenticationFilter.jwtUtil=(JwtUtil) webApplicationContext.getBean(JwtUtil.class);

    }

}
